<%@ include file="/common/taglibs.jsp" %>
<%@page contentType="text/html;charset=UTF-8" %>
<%@page pageEncoding="UTF-8" %>
<%@taglib prefix="ozingAuth" uri="http://www.ozing.cn" %>

<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/menu/assets/skins/sam/menu.css"/>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/menu/menu-min.js"></script>
<script type="text/javascript" src="/static/scripts/menu.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
         $('.yuimenubaritem').each(function() {
             if ($(this).find('ul li').length == 0) {
                 $(this).hide();
             }
         });
    });
</script>
<style type="text/css">
    div.yui-b p {
        margin: 0 0 .5em 0;
        color: #999;
    }

    div.yui-b p strong {
        font-weight: bold;
        color: #000;
    }

    div.yui-b p em {
        color: #000;
    }

    h1 {
        font-weight: bold;
        margin: 0 0 1em 0;
        padding: .25em .5em;
        background-color: #ccc;
    }

    #menu_list {
        margin: 0 0 10px 0;
    }

</style>

<%@ page import="com.chinadrtv.user.model.User" %>
<%@ page import="org.springframework.security.core.context.SecurityContextHolder" %>
<%@ page import="com.chinadrtv.user.model.Role" %>
<%@ page import="java.util.Set" %>
<div id="menu_list" class="yuimenubar yuimenubarnav">
    <div class="bd">
        <ul class="first-of-type">
            <%
                User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
                boolean admin = false;
                boolean agent = false;
                Set<Role> roles = user.getRoles();
                for (Role role : roles) {
                    if (role.getName().equals("ROLE_ADMIN")) {
                        admin = true;
                    } else if (role.getName().equals("ROLE_OZING_AGENT") || role.getName().equals("ROLE_AGENT_ADMIN")) {
                        agent = true;
                    }
                }

                if (admin) {
            %>
            <li class="yuimenubaritem first-of-type"><a class="yuimenubaritemlabel" href="#xingkaMgt">星卡管理</a>

                <div id="xingkaMgt" class="yuimenu">
                    <div class="bd">
                        <ul>
                            <ozingAuth:hasAuth url="/ozing/card/job">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/card/job">生成卡管理</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/cards/present">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/cards/present">赠卡管理</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/card/batches">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/card/batches">批次管理</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/cards">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/cards">星卡查询</a></li>
                            </ozingAuth:hasAuth>
                        </ul>
                    </div>
                </div>
            </li>
            <li class="yuimenubaritem first-of-type"><a class="yuimenubaritemlabel" href="#userXingka">消费管理</a>

                <div id="userXingka" class="yuimenu">
                    <div class="bd">
                        <ul>
                            <ozingAuth:hasAuth url="/ozing/users/cards">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/users/cards">用户交易管理</a>
                            </li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/card/redeems">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/card/redeems">星卡充值历史</a>
                            </li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/card/txs">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/card/txs">星卡消费历史</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/card/freeOrder">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/card/freeOrder">免费消费历史</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/card/vipOrder">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/card/vipOrder">VIP消费历史</a></li>
                            </ozingAuth:hasAuth>
                        </ul>
                    </div>
                </div>
            </li>

            <li class="yuimenubaritem first-of-type"><a class="yuimenubaritemlabel" href="#auth">权限管理</a>
                <div id="auth" class="yuimenu">
                    <div class="bd">
                        <ul>
                            <ozingAuth:hasAuth url="/ozing/auth">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/auth">权限管理</a></li>
                            </ozingAuth:hasAuth>
                        </ul>
                    </div>
                </div>
            </li>

            <li class="yuimenubaritem first-of-type"><a class="yuimenubaritemlabel" href="#batch">Batch管理</a>

                <div id="batch" class="yuimenu">
                    <div class="bd">
                        <ul>
                            <ozingAuth:hasAuth url="/batch/jobs">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/batch/jobs">任务管理</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/ozing/job/trigger">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/ozing/job/trigger">手动执行</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/batch/jobs/executions">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/batch/jobs/executions">执行状态</a></li>
                            </ozingAuth:hasAuth>
                            <ozingAuth:hasAuth url="/batch/">
                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/batch/">REST API</a></li>
                            </ozingAuth:hasAuth>
                            <%--<li class="yuimenuitem"><a class="yuimenuitemlabel" href="/batch/files">文件上传</a></li>--%>
                        </ul>
                    </div>
                </div>
            </li>
            <%}%>
            <%if (agent){%>
                <li class="yuimenubaritem first-of-type"><a class="yuimenubaritemlabel" href="#salesterminal">销售终端管理</a>

                    <div id="salesterminal" class="yuimenu">
                        <div class="bd">
                            <ul>
                                <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/agent/salesterminal">销售终端查询</a></li>
                            </ul>
                        </div>
                    </div>
                </li>
            <%}%>
        </ul>
    </div>
</div>
